package com.team.teamuserservice.controller;


import cn.hutool.core.bean.BeanUtil;
import com.aliyun.oss.model.MultipartUpload;
import com.team.teamuserservice.entity.dto.UserDto;
import com.team.teamuserservice.entity.po.BizUserInfo;
import com.team.teamuserservice.service.IBizUserInfoService;
import com.team.teamuserservice.uitls.AliyunOSSOperator;
import com.team.teamuserservice.uitls.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDateTime;

/**
 * <p>
 * 用户信息 前端控制器
 * </p>
 *
 * @author cxs
 * @since 2025-07-09
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class BizUserInfoController {

    private final IBizUserInfoService userInfoService;


    /**
     * 保存一个新用户
     * 注意这里是登录成功默认执行的一个创建用户的操作 , 不涉及上传头像
     * @param userDto
     */
    @PostMapping("/add")
    public Result addUser(UserDto userDto){

        BizUserInfo bizUserInfo = BeanUtil.copyProperties(userDto, BizUserInfo.class);
        bizUserInfo.setUpdateTime(LocalDateTime.now());
        boolean save = userInfoService.save(bizUserInfo);
        if (save){
            return Result.success();
        }
        return Result.error("新增用户失败");
    }

    /**
     * 上传头像
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/upload")
    public Result upLoad(MultipartFile file , Long id) throws Exception {
        return userInfoService.upLoad(file,id);
    }

    /**
     * vue分页查询
     * @param userDto
     * @return
     */
    @GetMapping("/list")
    private Result selectUserList(UserDto userDto){
        return userInfoService.pageList(userDto);
    }

}
